package com.xzx.java.kit.weakreference;

import java.lang.ref.WeakReference;

/**
 * @version 1.0
 * @auther xinzhixuan
 * @date 2022/4/22 19:06
 */
public class TestWeakReference {
    public static void main(String[] args) throws InterruptedException {
        User user1 = new User("张三");
        User user2 = new User("李四");
        WeakReference<User> userWeakReference1 = new WeakReference<>(user1);
        WeakReference<User> userWeakReference2 = new WeakReference<>(user2);
        System.out.println(userWeakReference1.get());
        System.out.println(userWeakReference2.get());
        user1 = null;
        user2 = null;
        System.gc();
        System.out.println(userWeakReference1.get());
        System.out.println(userWeakReference2.get());
    }
}
